<?php

	require_once('../process/connect_db.php');
	$db = new bd("admins");
	$query="Select nom_torneig From admins";
	$t=$db->consulta($query);	
	
	$trobat = false;
	for ($i=0; $i < sizeof($t) && !$trobat; $i++) { 
		if($t[$i]['nom_torneig'] == $_GET['torneig']){
			$trobat = true;
		}
	}
	
	
	if(!$trobat)	header("Location: index.php");
	
	$query = "Select nom_db From admins Where nom_torneig = \"". $_GET['torneig']. "\"";
	$db_torneig = $db->consulta($query);	

	$db = new bd($db_torneig[0]['nom_db']);
?>

<html>
	<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Generador d'horaris</title>
        <link rel="stylesheet" type="text/css" href="../estils/style.css">
	</head>
    <body>

	    	<div id="capçal" class="ombra">
	    	
	    		<h1 id="h1_head"> Generador d'horaris<h1>

			</div>
		

		<div  id="main" class="ombra">
			<div id="menu">
				<ul>
					<li class="nivell1"><a class="nivell1" href="../forms/index.php">Inici</a></li>
					<li class="nivell1"><a class="nivell1" href="#">Participants</a>
						<ul class="pestanya"><span></span>
							<li><a href="../forms/f_select_torneig.php">Inscriure's</a></li>
							<li><a href="#">Informació</a></li>
							<li><a href="#">Fotos</a></li>
						</ul>
					</li>
					<li class="nivell1"><a class="nivell1" href="#">Organització</a>
						<ul class="pestanya"><span></span>
							<li><a href="../forms/f_admin.php">Administrar torneig</a></li>
							<li><a href="#">Crear torneig</a></li>
						</ul>
					</li>
				</ul>
			</div>	


			<?php 
				print_r($_GET);
				
				$n_dnis = 0;
				foreach ($_GET as $key => $value) {
					if(substr($key, 0, 3) == "dni")	$n_dnis++;
				}
				
				$query = "Select * From info";
				$aux = $db->consulta($query);
				$info = $aux[0];
			?>

			
			<br>

			<h3> Incripció <?php echo $_GET['torneig']?></h3>
			<form name="inscrip" action="../process/p_nou_dni.php" method="POST" accept-charset="utf-8">
				Nom equip: <?php echo $_GET['equip']?><br>
				Categoria: <?php echo $_GET['cat']?><br><br>
				<font size="2" color="red">Falten les dades referents als següents usuaris: </font><br>
				

						<?php
							for ($i=0; $i < $n_dnis; $i++) { 
						?>
							<input type="hidden" name="dni<?php echo $i;?>" value="<?php echo $_GET['dni'.$i];?>">
							
							<h4>Dni: <?php echo $_GET['dni'.$i];?> </h4>
							Nom:     <input type="text"  placeholder="Nom Cognom" required="required" autofocus="autofocus" name="nom<?php echo $i;?>"> <br>
							Telefon: <input type="tel" placeholder="123456789" required="required" autofocus="autofocus"name="tel<?php echo $i;?>"> <br>
							
							
							E-mail:  <input type="email"  placeholder="nom@correu.com" required="required" autofocus="autofocus" name="correu<?php echo $i;?>"> <br>
							Sexe: 
							<select name="sexe<?php echo $i;?>">
								<option value="masc"> Masculí </option>
								<option value="fem"> Femaní </option>
							</select> <br>
							Nivell:
							<select name="nivell<?php echo $i;?>">
								<option value="inf"> Infantil </option>
								<option value="cast"> Costellada </option>
								<option value="obert"> Obert </option>
								<option value="elit"> Èlit </option>
							</select> <br><br>
							<b>Restriccions horaries: </b><font size="2" color="red">Marca les franges no disponibles (màxim 2) </font><br>
							Divendres 29: 
							<input type="checkbox" name="check_0_0_<?php echo $i;?>" value="dia0_0"> 17 - 22<br>
							Dissabte 30: 
							<input type="checkbox" name="check_1_0_<?php echo $i;?>" value="dia1_0"> 9 - 13
							<input type="checkbox" name="check_1_1_<?php echo $i;?>" value="dia1_1"> 13 - 17
							<input type="checkbox" name="check_1_2_<?php echo $i;?>" value="dia1_2"> 17 - 22<br>
							Diumenge 1: 
							<input type="checkbox" name="check_2_0_<?php echo $i;?>" value="dia2_0"> 9 - 13
							<input type="checkbox" name="check_2_1_<?php echo $i;?>" value="dia2_1"> 13 - 17<br>
							
							<br>
						<?php
							}
						?>


				
				<input type="hidden" name="torneig" value="<?php echo $_GET['torneig']?>">
				<input type="hidden" name="cat" value="<?php echo $_GET['cat']?>">
				<input type="hidden" name="equip" value="<?php echo $_GET['equip']?>">
				
				<input type="submit" value="Enviar">
			<form>
		</div>

    </body>
</html>